import {observable, action} from 'mobx'
import * as API_LIST from '../../apis/customReport/customReport'
import * as FnaMessage from '../../public/FnaMessage'
import {ConstantStatus,Permission} from '../../public/FnaConstant'
import cloneDeep from 'lodash/cloneDeep';
import { WeaLocaleProvider } from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

/**
 * 自定义报表页面Store
 */
export class CustomReportStore {

	constructor(){
	}

  @observable loading = false;

  /** 路由 **/
  router = {};

  //编辑Modal传入的数据
  @observable editData = {};

  @observable hasRight;//权限的标记 4无权限，跳转

  //主tab信息
  tab = [{
          groupid: 'flowAll',
          title: getLabel(388933,'查看全部'),
          viewcondition: 0
      }];

  @observable selected = 0; //选中的tab
  tabCount = 1; //tab数量
    
  @observable reportConfig = [];
  //报表条件配置项
  @observable showAll = false;

	//存为模板的
	@observable visibleTemp = false;

	setvisibleTemp = (value) => {
		this.visibleTemp = value;
  }
/************************CustomReport************************** */
  //列表数据
  initDatas = (value) => {
        //this.getTab(value);
        this.getCondition(value);
	}
    
    //获取Condition
  getCondition = (value = {},callBack) => {
        this.loading = true;
        API_LIST.getCondition(value).then( data => {
            let {status,configs} = data;
            if(status == ConstantStatus.FNA_RESULT_SUCCESS){
                this.hasRight = Permission.FNA_HASRIGHT;

                console.log('configs',configs);
                // let configa = cloneDeep(configs);
                // let configb = cloneDeep(configs);

                // configa.map((item,index)=>{
                //     item['key'] = '0a14e42c7655467a8d527b3caa994c84'+'_'+item['key'];
                //     item['accountId'] = '0a14e42c7655467a8d527b3caa994c84';
                // });

                // configb.map((item,index)=>{
                //     item['key'] = 'c096e927991947428d3fa7424be443a6'+'_'+item['key'];
                //     item['accountId'] = 'c096e927991947428d3fa7424be443a6';
                // });

                // this.reportConfig = [...configa,...configb];

                // configs.map((item,index)=>{
                //     item['key'] = '0a14e42c7655467a8d527b3caa994c84'+'_'+item['key'];
                //     item['accountId'] = '0a14e42c7655467a8d527b3caa994c84';
                // });

                this.reportConfig = configs;

                callBack && callBack();
            } else if(status == ConstantStatus.FNA_RESULT_HAS_NO_RIGHT){//没有权限
                this.hasRight = Permission.FNA_NORIGHT;
            }    
            this.loading = false;
        });
	}

	//存为模板
  saveToTemple = (value = {},flag = true) => {
        this.loading = true;
        API_LIST.saveToTemple(value).then( data => {
            let {status} = data;
            if(status == ConstantStatus.FNA_RESULT_SUCCESS){

                
            } else if(status == status == ConstantStatus.FNA_RESULT_FAILED){
				FnaMessage.fnaWarning(errorInfo);
            }    
            this.loading = false;
        });
  }
  
   //删除
   doDelete = (value = {},callback) => {
    this.loading = true;
    API_LIST.doDelete(value).then( data => {
        let {status,msg} = data;
        if(status == ConstantStatus.FNA_RESULT_SUCCESS){
            callback && callback();
            FnaMessage.fnaSuccess(msg);
        } else if(status == ConstantStatus.FNA_RESULT_FAILED){
            FnaMessage.fnaWarning(msg);
        }
        this.loading = false;
    });
 }
  /************************************************** */

    //保存编辑的Record
    setEditData = (value) => {
        this.editData = value;
   	}
	
	  setRouter = (value) => {
        this.router = value;
    }

    setReportConfig = (value) => {
      this.reportConfig = value;
    }

    setLoading = (value) => {
      this.loading = value;
    }
    
  /***********暂时不要************ */
  //获取Tab
  getTab = (value = {},callBack) => {
    this.loading = true;
    API_LIST.getTab(value).then( data => {
        let {status} = data;
        if(status == ConstantStatus.FNA_RESULT_SUCCESS){
            this.tabCount = data.tab.length;
            this.tab = data.tab;
            this.selected = selected;

            callBack && callBack();
        } else if(status == ConstantStatus.FNA_RESULT_HAS_NO_RIGHT){//没有权限
            this.hasRight = Permission.FNA_NORIGHT;
        }    
        this.loading = false;
    });
  }

}